from com.arcfox.school.util.jzy_decrypt_util import decrypt_font


class ProvinceScoreParse:
    def __init__(self):
        super().__init__()

    def parse_province_score_url_list(self, povince_map, university_id):
        query_list = []
        for povince in povince_map:
            p_code = povince_map[povince]
            item_url = f"http://www.juzhiyuan.com/index/school/ajax_scores?jzy_code={university_id}&province={p_code}&year=0&kemu=0"
            query_list.append({
                "url": item_url,
                "povince_name": povince,
                "povince_code": p_code
            })
        return query_list

    def parse_score_result_list(self, json, university_name):
        result_list = []
        data_arr = json["data"]
        for data in data_arr:
            subject_item = "文科"
            if data["kemu"] == 2:
                subject_item = "理科"
            if data["kemu"] == 3:
                if data["kemu_nums_descs"] == "":
                    subject_item = "综合"
                else:
                    subject_item = data["kemu_nums_descs"]
            result_list.append({
                "score_year": data["year"],
                "university_name": university_name,
                "province": data["provincesName"],
                "batch_name": data["batch_name"],
                # v-text="(item.kemu==1||item.kemu==2)?(item.kemu==1?'文科':'理科'): (item.kemu==3?(item.kemu_nums_descs?item.kemu_nums_descs:'综合'):item.kemu)">
                "subject_item": subject_item,
                "min_score": decrypt_font(data["min_score"]),
                "min_rank": decrypt_font(data["min_rank"]),
                "enroll_count": decrypt_font(data["luqu_num"]),
            })
        return result_list

    def parse_province_line_score_result_list(self, json, povince_map):
        province_score_list = []
        data_arr = json["data"]
        for data in data_arr:
            subject_item = "文科"
            if data["kemu"] == 2:
                subject_item = "理科"
            if data["kemu"] == 3:
                if data["kemu_nums_descs"] == "":
                        subject_item = "综合"
                else:
                    subject_item= data["kemu_nums_descs"]
            province = data["provincesName"]
            p_code = povince_map[province]
            province_score_list.append({
                "score_year": data["year"],
                "province_name": province,
                "province_code": p_code,
                "score_level": decrypt_font(data["line_score"]),
                "batch_name": data["batch_name"],
                "subject_item": subject_item,
            })
        return province_score_list
